﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;

namespace WF.Common
{
    public class Messages
    {
        public Messages()
        {

        }

        public static void ShowMessage(System.Web.UI.Page page, string message, bool isAlertMessage)
        {
            if (isAlertMessage)
            {
                //page.Response.Write("<script language='javascript'>alert(\"" + message + "\")</script>");
                page.ClientScript.RegisterStartupScript(page.GetType(), "Message", "<script language='javascript'>alert(\"" + message + "\")</script>", false);
            }
            else
            {
                if (page.FindControl("lblErrorMessage") != null)
                {
                    Label lblErrorMsg = (Label)page.FindControl("lblErrorMessage");
                    lblErrorMsg.Visible = true;
                    lblErrorMsg.Text = message;
                }
            }
        }

        public static void ShowMessage(System.Web.UI.Control control, string message, bool isAlertMessage)
        {
            if (isAlertMessage)
            {
                //page.Response.Write("<script language='javascript'>alert(\"" + message + "\")</script>");
                System.Web.UI.ScriptManager.RegisterStartupScript(control, control.GetType(), "Message", "<script language='javascript'>alert(\"" + message + "\")</script>", false);
            }
            else
            {
                if (control.FindControl("lblErrorMessage") != null)
                {
                    Label lblErrorMsg = (Label)control.FindControl("lblErrorMessage");
                    lblErrorMsg.Visible = true;
                    lblErrorMsg.Text = message;
                }
            }
        }

        public static void AjaxDialogRedirect(System.Web.UI.Control control, string url)
        {
            string script = "<script type='text/javascript'>window.returnValue = \"" + url + "\";</script>";
            System.Web.UI.ScriptManager.RegisterStartupScript(control, control.GetType(), "Redirect", script, false);

        }

        public static void AjaxShowMessage(System.Web.UI.Control control, string message, bool isAlertMessage)
        {
            if (isAlertMessage)
            {

                //page.Response.Write("<script language='javascript'>alert(\"" + message + "\")</script>");
                //page.ClientScript.RegisterStartupScript(page.GetType(), "Message", "<script language='javascript'>alert(\"" + message + "\")</script>", false);
                string script = "alert(\"" + message + "\");";
                System.Web.UI.ScriptManager.RegisterStartupScript(control, control.GetType(), "Message", script, true);

            }
            else
            {
                if (control.FindControl("lblErrorMessage") != null)
                {
                    Label lblErrorMsg = (Label)control.FindControl("lblErrorMessage");
                    lblErrorMsg.Visible = true;
                    lblErrorMsg.Text = message;
                }
            }
        }

        public static string ShowMsg(string strMsg)
        {

            return String.Format("<script language={1}javascript{1}>alert({1}{0}{1});</script>", strMsg, "\"");
        }


        /// <summary>
        /// 发送及时消息

        /// </summary>
        /// <param name="msgTo"></param>
        /// <param name="msg"></param>
        public static void SendIM(string msgTo, string msg)
        {
            string authorizationCode = "CentaIT5DEEF2BF-ACE4-44E5-9401-5056859A4DCA";
            WF.LCSService.LCSService im = new WF.LCSService.LCSService();
            im.Url = System.Configuration.ConfigurationManager.AppSettings["LCSServiceURL"];
            im.SendMessage(authorizationCode, msgTo, "", msg);
        }


        /// <summary>
        /// 发送邮件

        /// </summary>
        /// <param name="MessageTo"></param>
        /// <param name="MessageSubject"></param>
        /// <param name="MessageBody"></param>
        public static void SendMail(string MessageTo, string MessageSubject, string MessageBody)
        {
            WF.SendMailService.Mail mail = new WF.SendMailService.Mail();
            mail.Url = System.Configuration.ConfigurationManager.AppSettings["SendMailServiceURL"]; ;
            mail.SendMail(MessageSubject, MessageBody, MessageTo);

        }
    }
}
